home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / honeytrouble.swf / scripts / __Packages / Ball.as next >
Encoding:
Text File  |  2007-09-27  |  2.0 KB  |  79 lines

  1. class Ball
  2. {
  3.    var holder;
  4.    var x;
  5.    var y;
  6.    var type;
  7.    var dx;
  8.    var dy;
  9.    var sht_val;
  10.    var broadcastMessage;
  11.    static var parentMC;
  12.    static var holder_width;
  13.    static var shootSpeed;
  14.    static var sceneWidth;
  15.    static var sceneHeight;
  16.    static var timer;
  17.    function Ball(mc, id, __x, __y, _type)
  18.    {
  19.       this.holder = Ball.parentMC.attachMovie(mc,"b" + id,id + 1000);
  20.       this.holder.setMask(_root.center_mc.mask);
  21.       this.x = __x;
  22.       this.y = __y;
  23.       this.holder._x = this.x;
  24.       this.holder._y = this.y;
  25.       this.holder._width = this.holder._height = Ball.holder_width;
  26.       this.type = _type;
  27.       this.holder.gotoAndStop(this.type);
  28.       AsBroadcaster.initialize(this);
  29.    }
  30.    static function init(pMC, speed, width, height, ball_width, _timer)
  31.    {
  32.       Ball.parentMC = pMC;
  33.       Ball.shootSpeed = speed;
  34.       Ball.sceneWidth = width + Ball.shootSpeed;
  35.       Ball.sceneHeight = height + Ball.shootSpeed;
  36.       Ball.holder_width = ball_width;
  37.       Ball.timer = _timer;
  38.    }
  39.    function shoot(x, y)
  40.    {
  41.       var _loc2_ = undefined;
  42.       _loc2_ = Ball.shootSpeed / Math.sqrt(x * x + y * y);
  43.       this.dx = x * _loc2_;
  44.       this.dy = y * _loc2_;
  45.       this.sht_val = setInterval(this,"shootStep",Ball.timer);
  46.    }
  47.    function shootStep()
  48.    {
  49.       this.x += this.dx;
  50.       this.y += this.dy;
  51.       if(this.outOfScene())
  52.       {
  53.          this.broadcastMessage("shootFinish",this);
  54.          this.clearBall();
  55.       }
  56.       else
  57.       {
  58.          this.holder._x = this.x;
  59.          this.holder._y = this.y;
  60.          this.broadcastMessage("shootStep",this);
  61.       }
  62.       updateAfterEvent();
  63.    }
  64.    function clearBall()
  65.    {
  66.       clearInterval(this.sht_val);
  67.       this.holder.removeMovieClip();
  68.       false;
  69.    }
  70.    function moveStop()
  71.    {
  72.       clearInterval(this.sht_val);
  73.    }
  74.    function outOfScene()
  75.    {
  76.       return this.x < - Ball.shootSpeed || this.y < - Ball.shootSpeed || this.x > Ball.sceneWidth || this.y > Ball.sceneHeight;
  77.    }
  78. }
  79.